var config = require('../../config');
var mongoose = require('mongoose');
var mongodb;

mongoose.connect(config.mongodburl, config.mongodboptions, function(err, res) {
    if (err) {
        console.log('[mongoose log] Error connecting to: ' +config.mongodburl + '. ' + err);
        return process.exit(1);
    } else {
        return console.log('[mongoose log] Successfully connected to: ' +config.mongodburl);
    }
});

mongodb = mongoose.connection;

mongodb.on('error', console.error.bind(console, 'mongoose connection error:'));

mongodb.once('open', function() {
    return console.log('mongoose open success');
});


module.exports = mongodb;